import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:school_safe_teacher/constans/all_info.dart';
import 'package:school_safe_teacher/constans/route_constants.dart';
import 'package:school_safe_teacher/resourse/app_colors.dart';
import 'package:school_safe_teacher/widget/my_widget.dart';


import 'action.dart';
import 'state.dart';

Widget buildView(
    SettingState state, Dispatch dispatch, ViewService viewService) {
  return body(
      child: Container(
        color: AppColors.MainBackColor,
        child: Column(
          children: [
            Container(
              padding: EdgeInsets.only(left: 15, right: 15),
              child: noRightIconBar(context: viewService.context, title: "设置"),
              color: Colors.white,
            ),
            Expanded(child: _body(state, dispatch, viewService)),
          ],
        ),
      ),
      context: viewService.context);
}

Widget _body(SettingState state, Dispatch dispatch, ViewService viewService) {
  return Column(
    crossAxisAlignment: CrossAxisAlignment.center,
    mainAxisSize: MainAxisSize.min,
    children: [
      SizedBox(
        height: 10,
      ),
      Container(
        color: Colors.white,
        child: Column(
          children: [
            GestureDetector(
              child: Container(
                padding:
                    EdgeInsets.only(top: 15, bottom: 15, left: 25, right: 25),
                child: Row(
                  children: [
                    Text(
                      "修改密码",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.middleTextColor),
                    ),
                    Expanded(child: Text("")),
                    Image.asset(
                      "images/add_member_right@2x.png",
                      height: 10,
                      width: 5,
                    )
                  ],
                ),
              ),
              onTap: () {
                if (AllInfo.instance.token.isNotEmpty)
                  Navigator.of(viewService.context)
                      .pushNamed(RouteConstants.CHANGE_PWD);
                else
                  Navigator.of(viewService.context)
                      .pushNamed(RouteConstants.LOGIN);
              },
            ),
            Divider(
              height: 1,
            ),
            GestureDetector(
              child: Container(
                padding:
                    EdgeInsets.only(top: 10, bottom: 10, left: 25, right: 25),
                child: Row(
                  children: [
                    Text(
                      "用户隐私政策",
                      style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                          color: AppColors.middleTextColor),
                    ),
                    Expanded(child: Text("")),
                    Image.asset(
                      "images/add_member_right@2x.png",
                      height: 10,
                      width: 5,
                    )
                  ],
                ),
              ),
              onTap: () {
                //todo 隐私政策
                showToast("用户隐私政策");
              },
            ),
          ],
        ),
      ),
      SizedBox(
        height: 10,
      ),
      GestureDetector(
        child: Container(
          width: MediaQuery.of(viewService.context).size.width,
          color: Colors.white,
          padding: EdgeInsets.only(top: 15, bottom: 15),
          child: Text(
            "退出登录",
            textAlign: TextAlign.center,
            style: TextStyle(color: AppColors.LoginOutColor, fontSize: 15),
          ),
        ),
        onTap: () {
          dispatch(SettingActionCreator.onLogout());
        },
      )
    ],
  );
}
